<template>
  <j-modal :title="title" :visible="visible" :maskClosable="false" :fullscreen="true" @close="close">
    <template slot="footer">
      <a-button key="back" style="padding-left: 8px; padding-right: 8px" @click="close(false)"> 关闭 </a-button>
      <templete v-if="permissionInit && active == completeTab">
        <a-button
          :disabled="!!status &&  status != '0' && status != '1'"
          v-permission="['20080']"
          type="primary"
          @click="showConfirm"
          style="padding-left: 8px; padding-right: 8px"
        >
          完成实施阶段
        </a-button>
        <a-button
          :disabled="status !== '2'"
          v-permission="['20090']"
          @click="setApproveReason('9')"
          style="padding-left: 8px; padding-right: 8px"
        >
          同意
        </a-button>
        <a-button
          :disabled="status !== '2'"
          v-permission="['20090']"
          type="danger"
          @click="setApproveReason('1')"
          style="padding-left: 8px; padding-right: 8px"
        >
          拒绝
        </a-button>
        <a-button type="danger" key="save" style="padding-left: 8px; padding-right: 8px" @click="setReason()">
          撤销到准备阶段
        </a-button>
      </templete>
    </template>
    <div style="margin-bottom: 20px">
      <div class="detail">
        <div class="name">
          {{ model.name }}<span>{{ model.stageText }}</span>
        </div>
        <div class="list">
          <div>
            项目编号：<span>{{ model.number }}</span>
          </div>
          <div>
            项目类别：<span>{{ model.type_dictText }}</span>
          </div>
          <div>
            主审计单位：<span>{{ $store.getters.departInfo.departName }}</span>
          </div>
          <div>
            被审计单位：<span>{{ model.bsjdwName }}</span>
          </div>
          <div>
            审计期间：<span>{{ model.startDate }} ~ {{ model.endDate }}</span>
          </div>
        </div>
      </div>
    </div>
    <div style="margin: 0 auto" :class="{ isCheck: isCheck }">
      <a-tabs type="card" v-model="activeKey" @change="tabsChange" class="tabs_style">
        <a-tab-pane v-for="item in tabs" :key="item.key" :tab="item.title">
          <component
            v-if="isShow && active == item.key"
            :is="`${item.key}`"
            :id="model.id"
            :stage="model.stage"
            :protype="model.type"
            :bsjdwName="model.bsjdwName"
            :bsjdw="model.bsjdw"
            :type="viewTypeId[item.value]"
            :record="model"
            :isbanRouterParams="isbanRouterParams"
            :proName="model.name"
          >
          </component>
        </a-tab-pane>
      </a-tabs>
    </div>
    <SelectApprove ref="approver" :id="model.id" @submitData="handleSubmit"></SelectApprove>
    <SetReason ref="setReason" @approveReason="approveData"></SetReason>
    <SetReason ref="chSetReason" @approveReason="returnPro"></SetReason>
<!--    <AssistDrawer ref="AssistDrawer"></AssistDrawer>-->
    <ToolConfiguration ref="ToolConfiguration"></ToolConfiguration>
  </j-modal>
</template>
<script>
import cyxx from '../commView/cyxx/index'
import bcxsjws from '../commView/bcxsjws/index'
import bsjdwzl from '../commView/bsjdwzl/index'
import sjzxj from '../commView/sjzxj/index'
import shjl from '../commView/shjl/index'
import sssj from '../commView/sssj/index'
import sjcgzjsq from '../commView/sjcgzjsq/index'
import { WORK_AUTH } from '@/store/mutation-types'
import { getAction } from '@/api/manage'
import viewTypeId from '../commView/public/typeId'
import SetReason from '../commView/public/SetReason'
import SelectApprove from '../commView/public/SelectApprover'
import { butStatus } from '../butStatus'
import AssistDrawer from '@/views/sj/sjxmzygl/sjxmss/AssistDrawer'
import jumpConfig from '@/views/sj/sjxmzygl/sjxmss/jumpConfig'
import ToolConfiguration from '@/views/sj/sjxmzygl/sjxmzb/ToolConfiguration.vue'
export default {
  name: 'contentView',
  components: {
    cyxx,
    bcxsjws,
    bsjdwzl,
    sjzxj,
    shjl,
    sssj,
    sjcgzjsq,
    SetReason,
    SelectApprove,
    AssistDrawer,
    ToolConfiguration,
  },
  mixins: [butStatus],
  data() {
    return {
      active: 'cyxx',
      activeKey: 'cyxx',
      completeTab:'sssj',
      permissionInit: false,
      viewTypeId: viewTypeId,
      typeId: viewTypeId['审计实施阶段整体'],
      disableSubmit: false,
      //isbanRouterParams 禁止使用路由参数   true：标识使用路由参数，false：标识不适用路由参数
      isbanRouterParams: false,
      title: '',
      visible: false,
      isCheck: false,
      url: {
        returnPro: '/sjxmzygl/sjWorkUsers/recallLastStage',
        permission: '/sys/permission/getButtonByUser',
        submit: '/sjxmzygl/sjWorkUsers/submitAudit',
        approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
        butStatus: '/sjxmzygl/sjWorkUsers/queryStageInfo',
      },
      model: {},
      tabs: [
        { key: 'cyxx', title: '成员信息', value: '成员信息' },
        { key: 'bsjdwzl', title: '被审计单位资料', value: '被审计单位资料' },
        { key: 'sssj', title: '实施审计', value: '审计分工' },
        { key: 'sjzxj', title: '组小结', value: '组小结' },
        { key: 'bcxsjws', title: '审计参考资料', value: '审计文书模板' },
        // { key: 'sjcgzjsq', title: '审计成果组件授权', value: '' },
        { key: 'shjl', title: '审核记录', value: '审计实施阶段整体' },
      ],
      isShow: false,
    }
  },
  mounted() {
    this.$bus.$on('handleJumpRouter', this.handleJumpRouter)
  },
  beforeDestroy() {
    this.$bus.$off('handleJumpRouter')
  },
  methods: {
    async handleJumpRouter(pathname, componentName = '') {
      //  生成传递参数对象
      // debugger
      let params = await jumpConfig(pathname, componentName, this.model)
      if (Object.keys(params).length == 4) {
        // this.$refs.ToolConfiguration.show(this.model)
        this.$message.warning('请在审计项目管理设置辅助作业工具配置项')
      }
      this.$router.push({
        name: pathname,
        params,
      })
    },
    tabsChange(key) {
      this.active = key
    },
    getWorkAuth() {
      this.isShow = false
      this.permissionInit = false
      getAction(this.url.permission, { proId: this.model.id }).then((res) => {
        if (res.success) {
          this.isShow = true
          let workAuthData = res.result.workButtonAuth
          sessionStorage.setItem(WORK_AUTH, JSON.stringify(workAuthData))
          this.permissionInit = true
        }
      })
    },
    edit(record, isbanRouterParams) {
      this.model = Object.assign({}, record)
      this.getWorkAuth()
      this.getStstus()
      this.isbanRouterParams = isbanRouterParams
      if (this.$route.query && this.$route.query.activeKey && isbanRouterParams) {
        let { activeKey, activeMenu } = this.$route.query
        this.active = activeKey
        this.activeKey = activeKey
      } else {
        this.active = 'cyxx'
        this.activeKey = 'cyxx'
      }
      this.visible = true
    },
    close() {
      this.visible = false
    },
    setReason() {
      this.$refs.chSetReason.setApproveReason = true
    },
    //撤回
    returnPro(reason) {
      getAction(this.url.returnPro, {
        proId: this.model.id,
        typeId: this.typeId,
        stage: '01020',
        remark: reason,
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.$refs.chSetReason.setApproveReason = false
          this.$emit('ok')
          this.close()
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
}
</script>

<style lang='less' scoped>
@import '~@assets/less/tableTheme.less';
@import '../../css/checkAndEdit.less';

/deep/.ant-modal-body {
  position: relative;
}
</style>
